package ink.metoo.gude.properties

import ink.metoo.gude.GudeServerApplication.Companion.BASE_CONFIG_PREFIX
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component
import java.nio.file.Path
import kotlin.io.path.createDirectories
import kotlin.io.path.exists

@Component
@ConfigurationProperties("${BASE_CONFIG_PREFIX}.general")
class GeneralProperties(

    val workDirectory: String = "${System.getProperty("user.home")}/.gude"

) {

    fun getWorkDirectoryPath(): Path {
        val workDirectory = Path.of(workDirectory)
        if (!workDirectory.exists()) {
            workDirectory.createDirectories()
        }
        return workDirectory
    }

}